namespace array_demo.Model
{
    public class LinkedStack1<E> : IStack<E>
    {
        private LinkedList1<E> LinkedList1;

        public LinkedStack1()
        {
            LinkedList1 = new LinkedList1<E>();
        }

        public int Count => LinkedList1.count;

        public bool IsEmpty => LinkedList1.isEmpty;

        /// <summary>
        /// 在栈的头读取一个元素，但是不删除它 
        /// </summary>
        /// <returns></returns>
        public E Peek()
        {
            return LinkedList1.GetFirst();
        }

        /// <summary>
        /// 出栈
        /// </summary>
        /// <returns></returns>
        public E Pop()
        {
            return LinkedList1.deleteFirst();
        }

        /// <summary>
        /// 入栈
        /// </summary>
        /// <param name="e"></param>
        public void Push(E e)
        {
            // 数组的头部添加元素 O1
            // 数组尾部 On
            LinkedList1.AddFirst(e);
        }

        public override string ToString()
        {
            return "stack" + LinkedList1.ToString() + "top";
        }
    }
}